package com._520it.crm.web.controller;

import com._520it.crm.domain.Client;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.ClientQueryObject;
import com._520it.crm.service.IClientService;
import com._520it.crm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 呆 on 2017/10/3.
 */
@Controller
@RequestMapping("/formalClient")
public class FormalClientController {
    @Autowired
    private IClientService clientService;
    @RequestMapping("")
    public String index(){
        return "formalClient";
    }



    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(ClientQueryObject qo)
    {
        return clientService.employeeQuery(qo);
    }

    @RequestMapping("/save")
    @ResponseBody
    public AjaxResult save(Client client)
    {
        try {
            clientService.insert(client);
            return new AjaxResult(true,"保存成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult("保存失败!");
        }

    }

    @RequestMapping("/update")
    @ResponseBody
    public AjaxResult update(Client client)
    {
        try {
            clientService.updateByPrimaryClient(client);
            return new AjaxResult(true,"更新成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult("更新失败!");
        }

    }





}
